import tkinter as tk
import tkinter.messagebox
from tkinter import *
from tkinter import ttk

# 创建窗体
win = Tk()
# 标题
win.title("模拟注册")

# 响应事件
def exits(): # 退出
    win.destroy()

def in_iog(): # 登录
    name = var_u.get() # 获取用户名
    pwd = var_p.get()
    age = var_a.get()
    sex = var_sex.get()
    hobby = ""
    if var_c1.get()=="游戏":
        hobby+=var_c1.get()
    if var_c2.get() == "睡觉":
        hobby += var_c2.get()
    if var_c3.get() == "吃饭":
        hobby += var_c3.get()
    check = cb.get()
    text = t.get("1.0","end")
    tk.messagebox.showinfo("注册成功！", message=f"{name} {pwd} {age} {sex} {hobby} {check} {text}")
    print(f"{name} {pwd} {age} {sex} {hobby} {check} {text}")

def clear():
    var_u.set("")  # 获取用户名
    var_p.set("")
    var_a.set("")
    var_sex.set("男")
    var_c1.set("c1")
    var_c2.set("c2")
    var_c3.set("c3")
    cb.current(0)
    t.delete("1.0","end")

# 大小
win.geometry("500x400")
# 排版
Label(win, text="用户名：", font=("宋体", 23), fg='#008B45').grid(row=0, column=0)
Label(win, text="密码：", font=("宋体", 23), fg='#008B45').grid(row=1, column=0)
Label(win, text="年龄：", font=("宋体", 23), fg='#008B45').grid(row=2, column=0)
Label(win, text="性别：", font=("宋体", 23), fg='#008B45').grid(row=3, column=0)
Label(win, text="爱好：", font=("宋体", 23), fg='#008B45').grid(row=4, column=0)
Label(win, text="密保问题：", font=("宋体", 23), fg='#008B45').grid(row=5, column=0)
Label(win, text="密保答案：", font=("宋体", 23), fg='#008B45').grid(row=6, column=0)
"""文本框"""
var_u = StringVar()
Entry(win, textvariable=var_u, font=("宋体", 23)).grid(row=0, column=1)
var_p = StringVar()
Entry(win, textvariable=var_p, font=("宋体", 23)).grid(row=1, column=1)
var_a = StringVar()
Entry(win, textvariable=var_a, font=("宋体", 23)).grid(row=2, column=1)
"""单选按钮"""
var_sex = StringVar()
var_sex.set("男")
Radiobutton(win, text="男", value="男", variable=var_sex, font=("宋体", 18)).place(x=150, y=120)
Radiobutton(win, text="女", value="女", variable=var_sex, font=("宋体", 18)).place(x=230, y=120)
"""多选框"""
var_c1 = StringVar()
Checkbutton(win, text="游戏", variable=var_c1, onvalue="游戏", offvalue="c1", font=("宋体", 18)).place(x=150, y=150)
var_c2 = StringVar()
Checkbutton(win, text="睡觉", variable=var_c2, onvalue="睡觉", offvalue="c2", font=("宋体", 18)).place(x=245, y=150)
var_c3 = StringVar()
Checkbutton(win, text="吃饭", variable=var_c3, onvalue="吃饭", offvalue="c3", font=("宋体", 18)).place(x=345, y=150)
"""下拉框"""
cb = ttk.Combobox(win, state="live", font=("宋体", 18))
cb['values'] = ["你最喜欢的人", "你的梦想"]
cb.current(0)  # 默认选择第一个
cb.place(x=150, y=190)
"""多行文本框"""
t = Text(win, width=25, height=1, font=("宋体", 18))
t.place(x=150, y=230)
"""按钮"""
Button(win, text="提交",command=in_iog,font=("宋体", 18)).place(x=150, y=270)
Button(win, text="退出",command=exits,font=("宋体", 18)).place(x=220, y=270)
Button(win, text="清空内容",command=clear,font=("宋体", 18)).place(x=300, y=270)
# 执行窗体
win.mainloop()
